package com.travel.controller.user;

import com.travel.constant.ApiConstants;
import com.travel.model.dto.auth.PasswordChangeRequest;
import com.travel.model.dto.common.ApiResponse;
import com.travel.model.dto.user.UserProfileUpdateDTO;
import com.travel.model.entity.auth.User;
import com.travel.service.Service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
//用户资料接口 , 获取个人资料, 更新个人资料
@Tag(name = "用户资料接口", description = "用户资料相关接口")
@RestController
@RequestMapping(ApiConstants.API_USER + "/profile")
@RequiredArgsConstructor
public class UserProfileController {
    private final UserService userService;

    @Operation(summary = "获取个人资料", description = "获取当前用户的个人资料")
    @GetMapping
    public User getProfile() {
        return userService.getCurrentUser();
    }

    @Operation(summary = "更新个人资料", description = "更新当前用户的个人资料，支持部分更新")
    @PutMapping
    public ApiResponse<User> updateProfile(@RequestBody UserProfileUpdateDTO updateDTO) {
        User updatedUser = userService.updateUserProfile(updateDTO);
        return ApiResponse.success(updatedUser);
    }

    @Operation(summary = "修改密码", description = "修改当前用户的登录密码")
    @PutMapping("/password")
    public void changePassword(
            @Parameter(description = "密码信息") 
            @Valid @RequestBody PasswordChangeRequest request) {
        userService.changePassword(request);
    }
} 